/*
Content: Master file for replication
Paper: "Immigrants Return Intentions and Labor Market Behavior when the Home Country is Unsafe"
Journal: Journal of Labor Economics
Authors: Jacopo Bassetto, Teresa Freitas-Monteiro
This version: June 6, 2025
Stata version: 18
*/


clear
clear mata 
clear matrix
set matsize 2000
capture log close 
set more off       // Assures the program not to 'BREAK'
set maxvar 8000


********************************************************************************
**# GLOBALS
********************************************************************************

global path ""


global datasoep "$path/"  // data folder for SOEP intermediate and final files
		global orig ""  // original folder for SOEP original data
		global final "" // final folder for SOEP final analysis
	
global dataevent "$path/"  // folder for event data
	global uppsala "$dataevent/uppsala"
	global globalterror "$dataevent/globalterror"
global codes ""		// folder with country_codes correspondence


global prog "$path/prog/replication_jole/GSOEP" 
global table "$path/tabs/replication_jole/GSOEP" 
global graph "$path/figs/replication_jole/GSOEP" 
global log "$path/log"


capture log close
cd "$path"


********************************************************************************
**# ADOS
********************************************************************************

adopath ++ ""  // path for ados


********************************************************************************
**# DATA REQUIREMENT
********************************************************************************

	/*
	Original Datasets: 
	
	- GLOBAL TERROR DATABASE: for the paper we used the version from 1970-2017, downloaded November 19, 2020
	- UPPSALA CONFLICT DATA: UCDP Georeferenced Event Dataset, downloaded May 8, 2024
	- German Socio-Economic Panel: version 2018 (v35)
	
	*******
	
	Support Datasets: 
	
	- Correspondence table between country codes in event datasets and GSOEP country identifiers: 
		-> countrycodes_soep_armedconflict.dta
		-> countrycodes_soep_terror.dta
	*/


********************************************************************************
**# EVENT DATA PREPARATION
********************************************************************************
do "$prog/1_1_SOEP_event_prep_final.do"
do "$prog/1_2_SOEP_create_monthly_events_final.do"
do "$prog/1_3_SOEP_create_daily_events_final.do"


********************************************************************************
**# SOEP DATA PREPARATION
********************************************************************************

do "$prog/2_1_SOEP_master_porigin_final.do"
do "$prog/2_2_SOEP_soep_events_final.do"

********************************************************************************
**# ANALYSIS
********************************************************************************
	
	// Note: in the header of each do-file we report which tables and figures of the manuscript are created 
	
do "$prog/3_SOEP_mainregressions_final.do"
do "$prog/4_SOEP_balance_intdist_final.do"
do "$prog/5_SOEP_heterogeneous_effects_final.do"
do "$prog/6_SOEP_placebo_final.do"
do "$prog/7_SOEP_robustness_final.do"
do "$prog/8_SOEP_otheroutcomes_final.do"
do "$prog/9_SOEP_basic_stats_final.do"
do "$prog/10_SOEP_dailyattacks_final.do"


